package com.skyrhyme.entity;

import lombok.Data;

@Data
/*
    权限判断及其他异常使用自定义错误码（调用方法参数传递）
      - `200` - 获取成功
      - `400` - 参数错误
      - `401` - token无效或过期
      - `403` - 权限不足
      - `500` - 服务器错误
*/
public class Result {
    private Integer code;
    private String msg;
    private Object data;
    public Result() {
    }

    public static Result error(String msg){
        Result res = new Result();
        res.setCode(500);
        res.setMsg(msg);
        return res;
    }
    public static Result error(int code,String msg){
        Result res = new Result();
        res.setCode(code);
        res.setMsg(msg);
        return res;
    }
    public static Result success(){
        return new Result();
    }
    public static Result success(String msg){
        Result success = new Result();
        success.setCode(200);
        success.setMsg(msg);
        success.setData(null);
        return success;
    }
    public static Result success(String msg , Object data){
        Result success = new Result();
        success.setCode(200);
        success.setMsg(msg);
        success.setData(data);
        return success;
    }
}
